<template>
  <!-- 设备管理 -->
  <div id="criReportRecDiv">
    <Breadcrumb content="危急值处理" />
    <el-container>
      <div class="padding-sm" style="width: 70%; padding-top: 10px">
        <el-scrollbar style="height: 100%">
          <el-descriptions :column="3" :labelStyle="{ width: '110px', background: '#fff', color: '#000', textAlign: 'center' }" :contentStyle="{ width: '130px' }" border>
            <template #title>
              <div class="smallToolTitle">病人信息
              </div>
            </template>
            <el-descriptions-item label="姓名">
              <vxe-input disabled v-model="criReportForm.patNa"></vxe-input>
            </el-descriptions-item>
            <el-descriptions-item label="性别">
              <!-- <vxe-input disabled v-model="criReportForm.sex"></vxe-input> -->
              <template #label>
              <span>性别</span>
            </template>
            <span> {{ criReportForm.sex === '1' ? '男' : criReportForm.sex === '2' ? '女' : '未知' }}</span>
            </el-descriptions-item>
            <el-descriptions-item label="年龄">
              <vxe-input disabled v-model="criReportForm.age"></vxe-input>
            </el-descriptions-item>
            <el-descriptions-item label="病历号">
              <vxe-input disabled v-model="criReportForm.patNo"></vxe-input>
            </el-descriptions-item>
            <el-descriptions-item label="就诊类别">
              <!-- <vxe-input disabled v-model="criReportForm.patType"></vxe-input> -->
              <template #label>
              <span>病人类型</span>
            </template>
            <div v-for="(item, index) in patTypeList" :key="index">
              <span v-if="item.code === criReportForm.patType">{{ item.name }}</span>
            </div>
            </el-descriptions-item>
            <el-descriptions-item label="床位号">
              <vxe-input disabled v-model="criReportForm.bedNo"></vxe-input>
            </el-descriptions-item>
          </el-descriptions>

          <el-descriptions :column="3" :labelStyle="{ width: '110px', background: '#fff', color: '#000', textAlign: 'center' }" :contentStyle="{ width: '130px' }" border>
            <template #title>
              <div class="smallToolTitle">检查信息
              </div>
            </template>
            <el-descriptions-item label="申请号">
              <vxe-input disabled v-model="criReportForm.requestNo"></vxe-input>
            </el-descriptions-item>
            <el-descriptions-item label="样本类型">
              <vxe-input disabled v-model="criReportForm.sampleTypeName"></vxe-input>
            </el-descriptions-item>
            <el-descriptions-item label="检测项目">
              <vxe-input disabled v-model="criReportForm.itemNa"></vxe-input>
            </el-descriptions-item>
            <el-descriptions-item label="申请科室">
              <vxe-input disabled v-model="criReportForm.deptNo"></vxe-input>
            </el-descriptions-item>
            <el-descriptions-item label="申请医生">
              <!-- <vxe-input disabled v-model="criReportForm.reqDoctor"></vxe-input> -->
              <VxePulldownSelection disabled class="employee-input-W" ref="employeeSelectRef" :url="'/api/sys/hisEmployee/finAllHisEmployeeList'" @confirmClick="SelectRowClick" :tableColumn="[
                        { title: '编号', field: 'code' },
                        { title: '名称', field: 'name' }
                      ]" :aimKeys="[
                        { formKey: 'code', rowKey: 'code' },
                        { formKey: 'name', rowKey: 'name' }
                      ]" :displayTexts="['name']" :displayTextObj="criReportForm.reqDoctor" />
            </el-descriptions-item>
            <el-descriptions-item label="申请时间">
              <vxe-input disabled v-model="criReportForm.reqTime"></vxe-input>
            </el-descriptions-item>
            <el-descriptions-item label="上报科室">
              <vxe-input disabled v-model="criReportForm.reportDeptNa"></vxe-input>
            </el-descriptions-item>
            <el-descriptions-item label="上报医生">
              <vxe-input disabled v-model="criReportForm.reportPersonNo"></vxe-input>
            </el-descriptions-item>
            <el-descriptions-item label="上报时间">
              <vxe-input disabled v-model="criReportForm.reportTime"></vxe-input>
            </el-descriptions-item>
            <el-descriptions-item :span="3" label="异常项目">
              <vxe-textarea disabled v-model="criReportForm.itemException"></vxe-textarea>
            </el-descriptions-item>
            <!-- <el-descriptions-item :span="3" label="检查所见">
              <vxe-textarea disabled v-model="criReportForm.remark"></vxe-textarea>
            </el-descriptions-item>
            <el-descriptions-item :span="3" label="检查诊断">
              <vxe-textarea disabled v-model="criReportForm.remark"></vxe-textarea>
            </el-descriptions-item> -->
            <el-descriptions-item :span="1" label="处理医生">
              <VxePulldownSelection class="employee-input-W" ref="employeeSelectRef" :url="'/api/sys/hisEmployee/finAllHisEmployeeList'" @confirmClick="SelectRowClick" :tableColumn="[
                        { title: '编号', field: 'username' },
                        { title: '名称', field: 'realname' }
                      ]" :aimKeys="[
                        { formKey: 'username', rowKey: 'username' },
                        { formKey: 'realname', rowKey: 'realname' }
                      ]" :displayTexts="['realname']" :displayTextObj="criReportForm.doctorPersonName" />
            </el-descriptions-item>
            <!-- <el-descriptions-item :span="2" /> -->

          </el-descriptions>
          <el-descriptions :column="3" :labelStyle="{ width: '110px', background: '#fff', color: '#000', textAlign: 'center' }" :contentStyle="{ width: '130px' }" border>
            <template #title>
              <div class="smallToolTitle">处理意见
              </div>
            </template>
            <el-descriptions-item label-class-name="lableClass" class-name="contentClass9" :span="9">
              <vxe-textarea v-model="criReportForm.treatmentMeasure" @focus="showTypeCodeDrawer(criReportForm,'xjpymsjg')" class='xjpymsjg'></vxe-textarea>
            </el-descriptions-item>
          </el-descriptions>

        </el-scrollbar>
        <div class="foote1r">
          <el-form :inline="true">
            <el-row>
              <el-col :offset="2">
                <el-form-item>
                  <vxe-button type="text" class="button-blue" icon="vxe-icon-save" :disabled="IsEmpty(criReportForm.id)" content="处理完成" @click="criReportHandle()"></vxe-button>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
      </div>
    </el-container>
  </div>
  <!-- 授权验证组件 -->
  <AuthValidateComp ref="AuthValidateCompRef" @unChkConfirm="unChkConfirm" />
  <CriTemplateDrawer ref="criTemplateDrawerRef" @sltDiagnosTempInfo="selectDiagnosTempInfo" />
</template>
<script setup lang="ts">
import Breadcrumb from '@/components/Breadcrumb.vue';
import { ref, reactive, getCurrentInstance, onMounted } from 'vue';
import { VxeMessage, VxeNotifyType } from '@/utils/CommonMessage'; //提示框
import VxePulldownSelection from '@/components/VxePulldownSelection.vue'; //引入下拉组件
import { IsEmpty, formatDateTime, autoIncrementNumber, notifyMessage, notifyType } from '@/utils/common';
import AuthValidateComp from '@/components/AuthValidateComp.vue'; //AuthValidateComp
import CriTemplateDrawer from './CriTemplateDrawer.vue';

let { proxy }: any = getCurrentInstance();
let criReportForm: any = reactive({});
let reviewerDoctor = '';
let AuthValidateCompRef = ref(null); //授权验证弹窗对象
let criTemplateDrawerRef = ref(null);
let patTypeList = reactive([]); //字典表:病人类型

// 医生名称（显示用）
const doctorName = ref('');

// 方法定义区 =============
onMounted(async () => {
  const query = proxy.$route.query as any;
  if (query.id) {
    criReportForm.id = query.id ? query.id : null;
    reviewerDoctor = query.reviewerDoctor ? query.reviewerDoctor : null;
    getCriReportList();
  }
  getDictPatTypeList();
});


//获取病人类型数据字典
function getDictPatTypeList() {
  patTypeList.length = 0;
  const url = '/api/sys/basDictDetail/findDictDetailList';
  proxy.$http
    .get(url, { params: { code: 'PATTYPE' } })
    .then((res: any) => {
      patTypeList.push(...res.data);
    })
    .catch((err: any) => {
      proxy.$alert(err, '提示');
    });
}

// 获取申请项目列表
function getCriReportList() {
  if (IsEmpty(criReportForm.id)) {
    VxeMessage('审核id不能为空', VxeNotifyType.error);
    return;
  }
  const url = '/cri/critical/report/findCriticalReportInfo';
  let obj = {
    id: criReportForm.id,
    isReviewed: 0
  };
  proxy.$http
    .post(url, obj)
    .then((res: any) => {
      if (!IsEmpty(res.data)) {
        Object.assign(criReportForm, res.data[0]);
        criReportForm.reviewerDoctor = reviewerDoctor;
      }
    })
    .catch((err: any) => {
      proxy.$alert(err, '提示');
    });
}
function criReportHandle() {
  // if (AuthValidateCompRef.value) {
  //   AuthValidateCompRef.value?.initPage(true, { username: reviewerDoctor, realname: reviewerDoctor });
  //   return;
  // }
  criticalReportChk();
}
function unChkConfirm(e: any) {
  criticalReportChk();
}
function criticalReportChk() {
  let url = '/cri/critical/report/criticalReportChk';
  proxy.$http
    .post(url, criReportForm)
    .then((res: any) => {
      if (res.status.code === 1) {
        VxeMessage(res.status.msg, VxeNotifyType.success);
        Object.assign(criReportForm, res.data);
      } else {
        VxeMessage(res.status.msg, VxeNotifyType.error);
      }
    })
    .catch((err: any) => {
      VxeMessage(err, VxeNotifyType.error);
    });
}

// 点击组件表格行(上报人员)
function SelectRowClick(e) {
  console.log(e.row.username);
  
  criReportForm.doctorPerson = e.row.username;
  console.log(criReportForm);
  
}

/**调起模板漂浮div选择框 */
function showTypeCodeDrawer(item, descType) {
  criTemplateDrawerRef.value.initPage(item, descType);
}
</script>

<style lang="scss" scoped>
#criReportRecDiv {
  .el-descriptions {
    margin-top: 10px;
    :deep(.lableClass) {
      width: 0;
      padding: 4px 0px;
      // border: none;
    }
    :deep(.contentClass9) {
      width: 100%;
    }

    .employee-input-W {
      text-indent: 0;
      width: 150px;
      .el-input {
        width: 150px;
      }
      .el-input__inner {
        padding: 0 4px;
      }
    }
  }

  .footer {
    position: fixed;
    bottom: 0;
    width: 100%;
    padding: 5px 0;
    box-shadow: 8px 8px 15px #909399;
    background-color: $bg-gray;
    z-index: 9999;
    .el-form {
      transform: translateX(5%);
    }
    .el-form-item {
      margin-bottom: 0;
      margin-right: 12px;
    }
  }

  :deep(.el-descriptions) {
    padding-left: 1px;

    .vxe-input--inner,
    .vxe-textarea--inner,
    .vxe-button {
      background-color: transparent;
    }
    .vxe-input--inner[disabled] {
      color: #000;
    }
  }
}
</style>